package com.atguigu.test;

import com.atguigu.bean.Boss;
import com.atguigu.bean.Yellow;
import com.atguigu.config.MainConfigAutowired;
import com.atguigu.config.MainConfigOfPropertyValues;
import com.atguigu.config.MainConfigProfile;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

public class IOCTest_Profile {


    //1. 使用命令行动态参数:在虚拟机参数位置加载 -Dspring.profiles.active=test
    //2.代码的方式激活某种环境
    @Test
    public void test01(){
        //1.创建一个applicationContext
        AnnotationConfigApplicationContext applicationContext =
                new AnnotationConfigApplicationContext();
        //2.设置需要激活的环境
        applicationContext.getEnvironment().setActiveProfiles("test","dev");
        //3.注册配置类
        applicationContext.register(MainConfigProfile.class);
        //4.启动刷新容器
        applicationContext.refresh();
        String[] beanNamesForType = applicationContext.getBeanNamesForType(DataSource.class);
        for (String s : beanNamesForType) {
            System.out.println(s+"=========");
        }
        Yellow bean = applicationContext.getBean(Yellow.class);
        System.out.println(bean);

        applicationContext.close();

    }

}
